package be.ipl.finito.domaine;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@SuppressWarnings("serial")
@Entity
@Table(name = "JETONS", schema = "FINITO")
public class Jeton implements Serializable, Comparable<Jeton> {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "jeton_id")
	private int id;

	private int valeur = 0;

	@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "jeton")
	private Collection<Case> cases = new ArrayList<Case>();

	protected Jeton() {

	}

	public Jeton(int valeur) {
		this.valeur = valeur;
	}

	public Collection<Case> getCases() {
		return cases;
	}

	public int getId() {
		return id;
	}

	public int getValeur() {
		return valeur;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Jeton other = (Jeton) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public int compareTo(Jeton o) {
		return this.valeur - o.valeur;
	}

}
